﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using System.Windows.Media.Imaging;
using System.IO;

namespace STEditor.Classes
{
    public class EmptyTile : STTile
    {
        
        public static STFrame EmptyImage { get; set; }

        static EmptyTile()
        {
            EmptyImage = CreateDefaultEmptyImage(); 
        }

        private static STFrame CreateDefaultEmptyImage()
        {

            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                drawingContext.DrawRectangle(Brushes.Black, null, new Rect(0, 0, 32, 32));
                drawingContext.DrawRectangle(null, new Pen(Brushes.White, 1), new Rect(0, 0, 32, 32));
            }

            PixelFormat pixelFormat = PixelFormats.Pbgra32;

            RenderTargetBitmap bitmap = new RenderTargetBitmap(32, 32, 96, 96, pixelFormat);
            bitmap.Render(drawingVisual);

            PngBitmapEncoder enc = new PngBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create(bitmap));

            MemoryStream ms = new MemoryStream();
            enc.Save(ms);

            BitmapImage bmp = new BitmapImage();
            bmp.BeginInit();
            bmp.StreamSource = ms;
            bmp.EndInit();

            return STFrame.CreateFromBitmapImage(bmp);

        }

        public override STFrame Image
        {
            get
            {
                return EmptyImage;
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
